﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.IO;

namespace PhoneManager
{
    [RunInstaller(true)]
    public class CustomInstall : System.Configuration.Install.Installer
    {
        protected override void OnBeforeUninstall(System.Collections.IDictionary savedState)
        {
            string RoamFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string LocalFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            string Path = RoamFolder;
            if (!Path.EndsWith("\\"))
            {
                Path += "\\";
            }

            try
            {
                if (Directory.Exists(Path + "Fernando Cerqueira"))
                {
                    string[] dirs = Directory.GetDirectories(Path + "Fernando Cerqueira\\", "PhoneManager*");
                    foreach (string item in dirs)
                    {
                        Directory.Delete(item, true);
                    }
                    dirs = Directory.GetDirectories(Path + "Fernando Cerqueira\\");
                    if (dirs == null || dirs.Length == 0)
                    {

                        string[] files = Directory.GetFiles(Path + "Fernando Cerqueira\\");
                        if (files == null || files.Length == 0)
                        {
                            Directory.Delete(Path + "Fernando Cerqueira", true);
                        }
                    }
                }
                if (Directory.Exists(Path + "Fernando_Cerqueira"))
                {
                    string[] dirs = Directory.GetDirectories(Path + "Fernando_Cerqueira\\", "PhoneManager*");
                    foreach (string item in dirs)
                    {
                        Directory.Delete(item, true);
                    }
                    dirs = Directory.GetDirectories(Path + "Fernando_Cerqueira\\");
                    if (dirs == null || dirs.Length == 0)
                    {

                        string[] files = Directory.GetFiles(Path + "Fernando_Cerqueira\\");
                        if (files == null || files.Length == 0)
                        {
                            Directory.Delete(Path + "Fernando_Cerqueira", true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

                SharedLib.MsgErro(ex.Message);
            }
            Path = LocalFolder;
            if (!Path.EndsWith("\\"))
            {
                Path += "\\";
            }

            try
            {
                if (Directory.Exists(Path + "Fernando Cerqueira"))
                {
                    string[] dirs = Directory.GetDirectories(Path + "Fernando Cerqueira\\", "PhoneManager*");
                    foreach (string item in dirs)
                    {
                        Directory.Delete(item, true);
                    }
                    dirs = Directory.GetDirectories(Path + "Fernando Cerqueira\\");
                    if (dirs == null || dirs.Length == 0)
                    {

                        string[] files = Directory.GetFiles(Path + "Fernando Cerqueira\\");
                        if (files == null || files.Length == 0)
                        {
                            Directory.Delete(Path + "Fernando Cerqueira", true);
                        }
                    }
                }
                if (Directory.Exists(Path + "Fernando_Cerqueira"))
                {
                    string[] dirs = Directory.GetDirectories(Path + "Fernando_Cerqueira\\", "PhoneManager*");
                    foreach (string item in dirs)
                    {
                        Directory.Delete(item, true);
                    }
                    dirs = Directory.GetDirectories(Path + "Fernando_Cerqueira\\");
                    if (dirs == null || dirs.Length == 0)
                    {

                        string[] files = Directory.GetFiles(Path + "Fernando_Cerqueira\\");
                        if (files == null || files.Length == 0)
                        {
                            Directory.Delete(Path + "Fernando_Cerqueira", true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

                SharedLib.MsgErro(ex.Message);
            }
            base.OnBeforeUninstall(savedState);
        }
    }
}
